
const getPickerTitle = (type, id, title='') => {
	const targetPickerData = getPicker(type);
	targetPickerData.forEach((item, key) => {
		if (item.id == id) {
			title = item.title;
			// console.log(":",type,title);
		}
	})
	// console.log(title);
	return title;
}

const getTitle = (list, id, title='') => {	
	list.forEach((item,key) => {
		if (item.id == id) {
			title = item.title;
		}
	})
	
	return title;
}

const getTitleByTag = (tag, id, title='') => {
	
	const targetPickerData = getPickerByTag(tag);
	targetPickerData.forEach((item, key) => {
		if (item.id == id) {
			title = item.title;
			// console.log(":",type,title);
		}
	});
	
	return title;
}

const getPicker = (type) => {
	const allPickerData = getAllPicker();
	
	return allPickerData[type] ? allPickerData[type] : [];
}

const getPickerByTag = (tag) => {
	let tags = ['sugar','wine','dessert','led','light','3d','rite'];
	if (!tags.includes(tag)) return [];
	let type = '';
	if (tag == 'rite') {
		type = 'ritualList';
	} else {
		type = tag + 'List';
	}
	
	const allPickerData = getAllPicker();
	
	return allPickerData[type] ? allPickerData[type] : [];
}

const getAllPicker = () => {
	let localData = localStorage.getItem('allPicker');
	const apiJson = JSON.parse(localData);
	
	return apiJson.data ? apiJson.data : {};
}

const changePicker = (_self) => {
	console.log('aa',_self);
}
const getRegion = () => {
	let region = [
		{ id: '802', title: '上海' },
		{ id: '1965', title: '广州' },
		{ id: '934', title: '杭州' },
		{ id: '821', title: '南京' },
		{ id: '861', title: '苏州' },
		{ id: '948', title: '宁波' },
		{ id: '818', title: '奉贤' }
	];
  
	return region;
  }
  
  const getRegionItem = (id, title='') => {
	let list = getRegion();
	let matched = list.find(ele => ele.id == id);
	if (matched) {
		title = matched['title'];
	}
	
	return title;
  }
const convertBanquetTypeToStr = (types = [], delimiter=',') => {
	let textArr = [];
	types.forEach(item => {
		if (item == 1) {
			textArr.push('午宴');
		}
		
		if (item == 2) {
			textArr.push('晚宴');
		}
	})
	
	return textArr.join(delimiter);
}
module.exports = {
	convertBanquetTypeToStr:convertBanquetTypeToStr,
	getTitle: getTitle,
	getTitleByTag:getTitleByTag,
	getPickerTitle: getPickerTitle,
	getPickerByTag:getPickerByTag,
	getPicker: getPicker,
	getAllPicker: getAllPicker,
	changePicker: changePicker,
	getRegion: getRegion,
	getRegionItem: getRegionItem
}
